package com.qf.team2.netdisc.common.base;

import com.qf.team2.netdisc.common.pojo.vo.RespResultVO;

/**
 * 控制器基础类
 *
 * @author Simon_Wong
 * @date 2021/05/20
 * @since 2021/5/20 9:59
 */
public class BaseController<T> {
    /**
     * 成功返回结果体
     *
     * @param data 数据
     * @param msg  消息语句
     * @return {@link RespResultVO<T>}
     */
    public RespResultVO<T> successResp(T data, String msg) {
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.SUCCESS.getValue());
        result.setData(data);
        result.setMessage(msg);
        return result;
    }

    /**
     * 失败返回结果体
     *
     * @param msg 消息语句
     * @return {@link RespResultVO<T>}
     */
    public RespResultVO<T> failedResp(String msg) {
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.FAILED.getValue());
        result.setMessage(msg);
        return result;
    }

    /**
     * 带有数据的失败返回结果体
     *
     * @param msg  消息语句
     * @param data 数据
     * @return {@link RespResultVO<T>}
     */
    public RespResultVO<T> failedRespWithData(T data, String msg) {
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.FAILED.getValue());
        result.setData(data);
        result.setMessage(msg);
        return result;
    }


    /**
     * 业务异常返回结果体
     *
     * @param msg 消息语句
     * @return {@link RespResultVO<T>}
     */
    public RespResultVO<T> businessResp(String msg) {
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.BUSINESS_EXCEPTION.getValue());
        result.setMessage(msg);
        return result;
    }

    /**
     * 带有数据的失败返回结果体
     *
     * @param msg  消息语句
     * @param data 数据
     * @return {@link RespResultVO<T>}
     */
    public RespResultVO<T> businessRespWithData(T data, String msg) {
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.BUSINESS_EXCEPTION.getValue());
        result.setData(data);
        result.setMessage(msg);
        return result;
    }

}
